//
//  LYBluetoothData.swift
//  RxSwift_Practice
//
//  Created by 李永彬 on 2020/5/14.
//  Copyright © 2020 李永彬. All rights reserved.
//

import Foundation

enum LYBlueToothdataType: Int {
    case LYBlueToothdataTypeNormal
    case LYBlueToothdataTypeMedia
    case LYBlueToothdataTypeAddressBook
    case LYBlueToothdataTypeExpand
}

@objc enum LYBluetoothDataState: Int {
    case LYBluetoothDataStatePlain
    case LYBluetoothDataStateSending
    case LYBluetoothDataStateSent
    case LYBluetoothDataStateSendFailed
    case LYBluetoothDataStateReciving
    case LYBluetoothDataStateRecived
    case LYBluetoothDataStateReciveFailed
    case LYBluetoothDataStateTimeout
};


protocol LYBluetoothDataDelegate: NSObject {
    //监测接收数据时超时
    func bluetoothDataNeedRefreshTimeout()
}

@objc public class LYBluetoothData: NSObject {
  
    /**
     发送数据
     */
    var sendData: Data?
    
    /**
     回调数据
     */
    var receivedData: Data?

    /**
     超时时间，默认10s
     */
    var timeout: TimeInterval?

    /**
     数据类型
     */ 
    var type: LYBlueToothdataType?
    var errorCode : LYBCCode?
    
    @objc dynamic var state: LYBluetoothDataState 
    
    var delegate: LYBluetoothDataDelegate?
    
    init(sendData: Data, timeout: TimeInterval = 10.0, type: LYBlueToothdataType) {
        self.sendData = sendData
        self.timeout = timeout
        self.type = type
        self.state = .LYBluetoothDataStatePlain
    }
    
    func refreshTimeout() {
        delegate?.bluetoothDataNeedRefreshTimeout()
    }
}
